package com.shhm.business.controller;

import com.shhm.business.dto.request.EvaluationReq;
import com.shhm.business.dto.response.EvaluationResp;
import com.shhm.business.service.EvaluationService;
import com.shhm.common.annotations.OperateLog;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.entity.common.EvaluationEntity;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: 评论管理控制器
 * @date 2025/9/14 下午11:46
 */
@RestController
//@RequestMapping("/admin")
public class EvaluationController {

    @Resource
    private EvaluationService evaluationService;

    /**
     * 管理端分页查看所有用户评论数据
     */
    @GetMapping("/admin/evaluation")
    public AjaxResultPlus pageList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage
    ){
        // 使用新的通用查询方法，管理员权限
        return evaluationService.pageList(pageNum, pageSize, isPage);
    }

    /**
     * 条件搜索评论列表
     */
    @PostMapping("/business/evaluation/search")
    public AjaxResultPlus pageSearchList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody EvaluationReq entity,
            @RequestParam(defaultValue = "1") Integer isPage
    ){
//        System.out.println("----->>>"+entity);
        return evaluationService.pageSearchList(pageNum, pageSize, isPage, entity);
    }

    /**
     * 用户发布评论数据
     */
    @PostMapping("/business/evaluation")
    @OperateLog(module="评论管理",type = "POST",desc = "添加系统评论信息")
    public AjaxResultPlus add(@RequestBody EvaluationEntity entity){
        return evaluationService.add(entity);
    }

    /**
     * 修改评论数据（包含管理端修改评论状态）
     */
    @PutMapping("/business/evaluation")
    @OperateLog(module="评论管理",type = "PUT",desc = "修改系统评论信息")
    public AjaxResultPlus update(@RequestBody EvaluationEntity entity){
        return evaluationService.update(entity);
    }

    /**
     * 根据ID删除评论数据
     */
    @DeleteMapping("/business/evaluation")
    @OperateLog(module="评论管理",type = "DELETE",desc = "删除系统评论")
    public AjaxResultPlus delete(@RequestBody RequestList ids){
        return evaluationService.delete(ids);
    }

    /**
     * 获取卖家的商品评论
     */
    @GetMapping("/business/product/evaluation/{sellerId}")
    public AjaxResultPlus getProductEvaluation(@PathVariable Integer sellerId){
        if (sellerId == null) {
            return AjaxResultPlus.warn("卖家ID不能为空");
        }
        EvaluationEntity entity = new EvaluationEntity();
        entity.setSellerId(sellerId);
//        return evaluationService.queryEvaluations(1, 10, 0, entity);
        return null;
    }
}
